/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PC;

import csse3004.GD.DA.PollCreatorDA;
import javax.servlet.ServletException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

/**
 *
 * @author s4200768 Lewis Kelly
 */
public class locationController extends SimpleFormController {
    protected final Log logger = LogFactory.getLog(getClass());
    private PollCreatorService pollCreatorService = new PollCreatorDA();
    
    
    @Override
    public ModelAndView onSubmit(Object command) throws ServletException {
        
        location loca = (location) command;
        double lat=loca.getLatitude();
        double lng=loca.getLongitude();
        int id = loca.getPollID();

        logger.info(lat);
        logger.info(lng);
        logger.info(id);
        
        
        pollCreatorService.addLocationToPoll(id, lat, lng);
        logger.info("returning location page");
        return new ModelAndView(new RedirectView(getSuccessView()));
    }
}